<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    protected string $tableName = 'admin_logs';

    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (Schema::hasTable($this->tableName)) {
            return;
        }
        Schema::create($this->tableName, function (Blueprint $table) {
            $table->comment('管理员操作日志表');
            $table->increments('id')->comment('主键ID');
            $table->integer('created_id')->default(0)->comment('');
            $table->integer('created_at')->default(0)->comment('');
            $table->integer('updated_id')->default(0)->comment('');
            $table->integer('updated_at')->default(0)->comment('');
            $table->integer('deleted_id')->default(0)->nullable()->comment('');
            $table->integer('deleted_at')->default(0)->nullable()->comment('');
            $table->string('content', 255)->default('')->comment('操作详细');
            $table->string('ip', 30)->default('')->nullable()->comment('操作时的ip');
            $table->string('url', 100)->default('')->nullable()->comment('日志访问的地址');
            $table->integer('related_id')->default(0)->nullable()->comment('关联表ID');
            $table->json('info')->nullable()->comment('明细');
            $table->tinyInteger('status')->default(0)->comment('状态 1-显示 2-隐藏 90-删除');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists($this->tableName);
    }
};
